package org.noote.libs.virtualpad;

public class Virtual9DPad extends VirtualTouchPad {
	
	protected boolean _bUpPressed = false;
	protected boolean _bDownPressed = false;
	protected boolean _bRightPressed = false;
	protected boolean _bLeftPressed = false;
	protected boolean _bUpRightPressed = false;
	protected boolean _bUpLeftPressed = false;
	protected boolean _bDownRightPressed = false;
	protected boolean _bDownLeftPressed = false;
	protected boolean _bCenterPressed = false;
	
	@Override
	protected void _checkButtons()
	{
		_bCenterPressed = false;
		_bUpPressed = false;
		_bDownPressed = false;
		_bRightPressed = false;
		_bLeftPressed = false;
		_bUpRightPressed = false;
		_bUpLeftPressed = false;
		_bDownRightPressed = false;
		_bDownLeftPressed = false;

		if(_iState == TOUCH_MOVED)
			_iState = TOUCH_PRESSED;

		if((_iState == TOUCH_RELEASED && _iOldState == TOUCH_PRESSED)
				|| (_iOldState == TOUCH_RELEASED && _iState == TOUCH_PRESSED))
			_bNewEvent = true;
		
		if(_iState == TOUCH_RELEASED) return;
		
		float fLimitMin = -0.33f;
		float fLimitMax = 0.33f;
		
		if(_fPosition_X>=fLimitMin && _fPosition_X<=fLimitMax
				&& _fPosition_Y>=fLimitMin && _fPosition_Y<=fLimitMax)
			_bCenterPressed = true;
		else if(_fPosition_X>fLimitMax && _fPosition_Y>=fLimitMin && _fPosition_Y<=fLimitMax)
			_bLeftPressed = true; 
		else if(_fPosition_X<fLimitMax && _fPosition_Y>=fLimitMin && _fPosition_Y<=fLimitMax)
			_bRightPressed = true; 
		else if(_fPosition_X>=fLimitMin && _fPosition_X<=fLimitMax && _fPosition_Y>fLimitMax)
			_bDownPressed = true; 
		else if(_fPosition_X>=fLimitMin && _fPosition_X<=fLimitMax && _fPosition_Y<fLimitMin)
			_bUpPressed = true; 
		else if(_fPosition_X>fLimitMax && _fPosition_Y>fLimitMax)
			_bDownLeftPressed = true; 
		else if(_fPosition_X>fLimitMax && _fPosition_Y<fLimitMin)
			_bUpLeftPressed = true; 
		else if(_fPosition_X<fLimitMin && _fPosition_Y>fLimitMax)
			_bDownRightPressed = true; 
		else if(_fPosition_X<fLimitMin && _fPosition_Y<fLimitMin)
			_bUpRightPressed = true; 
	}
	
	public boolean getButtonCenter(){return _bCenterPressed;}
	public boolean getButtonUp(){return _bUpPressed;}
	public boolean getButtonDown(){return _bDownPressed;}
	public boolean getButtonRight(){return _bRightPressed;}
	public boolean getButtonLeft(){return _bLeftPressed;}
	public boolean getButtonUpLeft(){return _bUpLeftPressed;}
	public boolean getButtonUpRight(){return _bUpRightPressed;}
	public boolean getButtonDownLeft(){return _bDownRightPressed;}
	public boolean getButtonDownRight(){return _bDownLeftPressed;}

}
